//
//  BannerView.m
//  time
//
//  Created by bingo on 2018/5/20.
//  Copyright © 2018年 1ge. All rights reserved.
//

#import "BannerView.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "AnnounceView.h"


@interface BannerView ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) AnnounceView *announceView;
@end
@implementation BannerView
- (SDCycleScrollView *)cycleScrollView{
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"飞艇"]];
        _cycleScrollView.delegate = self;
        _cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageHighlight"];
        _cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageNormal"];

    }
    return _cycleScrollView;
}



- (instancetype)init{
    if (self = [super init]) {
        [self setupUI];
        [self setupLayout];
    }
    return self;
}
#pragma mark- UI
- (void)setupUI{
    //3.添加公告
    self.announceView = [[AnnounceView alloc] init];
    self.announceView.cycleScrollView.clickItemOperationBlock = ^(NSInteger currentIndex) {
        if (_clickTitleBlock) {
            _clickTitleBlock(currentIndex);
        }
    };
    
}

- (void)setTitlesArr:(NSArray *)titlesArr {
    _titlesArr = titlesArr;
    
    _announceView.titlesArr = _titlesArr;
}

- (void)setDataArray:(NSArray *)dataArray {
    _dataArray = dataArray;
        
    _cycleScrollView.imageURLStringsGroup = _dataArray;
}

- (void)setupLayout{
    
/** 下边广告*/
    
    [self addSubview:self.announceView];
    [self.announceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset = 0;
        make.height.mas_equalTo(30);
    }];
    
    [self addSubview:self.cycleScrollView];
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.offset = 0;
        make.bottom.mas_equalTo(-30);
    }];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    if (_clickBannerBlock) {
        _clickBannerBlock(index);
    }
}


@end
